package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 采购单分录
 *
 * @author 文卡<wkwenka@gmail.com>  on 17-2-13.
 */
@Entity
@Table(name = "purchase_bill_entry")
public class PurchaseBillEntry extends BillEntry {

    @JSONField(serialize = false)
    @ManyToOne
    protected PurchaseBill owner;

    @Column(name = "state")
    private Integer state;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time")
    private Date createTime = new Date();

    @Transient
    private String sn; //所属单号

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Transient
    private Date bizdate;

    @Transient
    private String biztype;

    @Transient
    private String creator;

    @Transient
    private Integer ownerState;

    @Transient
    private String ownerRemark;

    @Transient
    private String goodsUnit;

    @Column(name = "purchase_price")
    private BigDecimal purchasePrice = BigDecimal.ZERO;

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public PurchaseBill getOwner() {
        return owner;
    }

    public void setOwner(PurchaseBill owner) {
        this.owner = owner;
    }

    public String getSn() {
        return owner == null ? this.sn : owner.getSn();
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public Date getBizdate() {
        return owner == null ? this.bizdate : owner.getBizdate();
    }

    public void setBizdate(Date bizdate) {
        this.bizdate = bizdate;
    }

    public String getBiztype() {
        return owner == null ? this.biztype : owner.getBizType();
    }

    public void setBiztype(String biztype) {
        this.biztype = biztype;
    }


    public String getCreator() {
        return owner == null ? this.creator : owner.getCreatorName();
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public Integer getOwnerState() {
        return owner == null ? this.ownerState : owner.getState();
    }

    public void setOwnerState(Integer ownerState) {
        this.ownerState = ownerState;
    }

    public String getOwnerRemark() {
        return this.owner != null ? this.owner.getRemark() : this.ownerRemark;
    }

    public void setOwnerRemark(String ownerRemark) {
        this.ownerRemark = ownerRemark;
    }

    public BigDecimal getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(BigDecimal purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public String getGoodsUnit() {
        return this.goods != null ? this.goods.getUnit() : this.goodsUnit;
    }

    public void setGoodsUnit(String goodsUnit) {
        this.goodsUnit = goodsUnit;
    }
}
